/*
 * @Author: xuhy 1727317079@qq.com
 * @Date: 2022-09-09 09:34:28
 * @LastEditors: xuhy 1727317079@qq.com
 * @LastEditTime: 2022-09-09 09:41:41
 * @FilePath: \vue3_test\src\hooks\usePoint.js
 * @Description: hook函数封装
 */
import { reactive, onMounted, onBeforeUnmount } from "vue";
export default function () {
  // 实现鼠标“打点”相关的数据
  let point = reactive({
    x: 0,
    y: 0,
  });
  // 实现鼠标“打点”相关的方法
  function savePoint(event) {
    point.x = event.pageX;
    point.y = event.pageY;
    console.log(event.pageX, event.pageY);
  }
  // 实现鼠标“打点”相关的生命周期钩子
  onMounted(() => {
    window.addEventListener("click", savePoint);
  });

  onBeforeUnmount(() => {
    window.removeEventListener("click", savePoint);
  });
  return point;
}
